<template>
<div class="bg-white">
 <el-row>
 <!-- <el-button  type="primary" size="small" icon="el-icon-plus" @click="add()">新建</el-button> -->
  <span>票类别：</span>
  <el-select filterable v-model="ticket" placeholder="请填写票码" >
    <el-option v-for="item in tickets" :label="item.organization" :value="item.organization + ',' + item.organizationValue" :key="item.id"></el-option>
  </el-select>
  &nbsp&nbsp
  <span>考核结果年份：</span>
  <el-input-number v-model="createdate" controls-position="right" :min="2021" :max="9999"></el-input-number>
  &nbsp&nbsp
  <span>考核结果次数年份：</span>
  <el-input-number v-model="ticketCount" controls-position="right" :min="1" :max="9999"></el-input-number>
  &nbsp&nbsp
  <span>岗位分类：</span>
  <el-select filterable v-model="identity" placeholder="请填写岗位分类">
    <el-option v-for="item in identityArr" :label="item.identity" :value="item.identity" :key="item.id"></el-option>
  </el-select>
  <!-- </br>
  &nbsp&nbsp
  <span>考核人员：</span>
  <el-input v-model="peopleName" placeholder="请填写考核人员" style="width: 20%;"></el-input>
  &nbsp&nbsp
  <span>现任职务：</span>
  <el-input v-model="currentPosition" placeholder="请填写现任职务"  style="width: 20%;"></el-input>
  &nbsp&nbsp
  <span>测评类别：</span>
  <el-select filterable v-model="appraisalPeopleVal" placeholder="请填写测评类别" >
    <el-option v-for="item in appraisalPeopleArr" :label="item.name" :value="item.value" :key="item.value"></el-option>
  </el-select>
  </br>
  &nbsp&nbsp
  <span>测评单位：</span>
  <el-select filterable v-model="appraisalUnitVal" placeholder="请填写测评单位" >
    <el-option v-for="item in appraisalUnit" :label="item.organization" :value="item.organization" :key="item.organization"></el-option>
  </el-select> -->
 </el-row>
  <el-table
    class="table"
    size = "small"
    :data="dataList">
     <el-table-column
      type="index"
      width="50">
    </el-table-column>
    <el-table-column
      prop="name"
      label="报表名">
    </el-table-column>
    <el-table-column
      prop="updateDate"
      label="更新日期">
      <template slot-scope="scope">
         {{moment(scope.row.updateDate).format('YYYY-MM-DD HH:mm:ss')}}
      </template>
    </el-table-column>
    <el-table-column label="操作">
      <template slot-scope="scope">
         <!-- <el-button
          size="mini"
          type="text"
          @click="pre(scope.row)" >预览</el-button>
           <el-divider direction="vertical"></el-divider> -->
      <el-button
          size="mini"
          type="text"
          @click="design(scope.row)" >设计</el-button>
           <el-divider direction="vertical"></el-divider>
        <!-- <el-button
          size="mini"
          type="text"
          @click="del(scope.row)" >删除</el-button>
           <el-divider direction="vertical"></el-divider> -->
           <el-button
          size="mini"
          type="text"
          @click="download(scope.row)" >导出</el-button>
      </template>
    </el-table-column>
  </el-table>
</div>
</template>
<script>
export default {
  data () {
    return {
      ticket: '',
      createdate: new Date().getFullYear(),
      ticketCount: 1,
      peopleName: '',
      dataList: [],
      searchTime: '',
      identityArr: [],
      identity: '',
      currentPosition: '',
      tickets: [],
      appraisalUnit: [],
      appraisalUnitVal: '',
      appraisalPeopleVal: '',
      appraisalPeopleArr: [
        {
          name: '反向测评',
          value: 'fan'
        },
        {
          name: '五整治',
          value: 'five'
        }
      ]
    }
  },
  activated () {
    this.refreshList()
  },
  methods: {
      // 获取数据列表
    refreshList () {
      this.loading = true
      this.$http({
        url: '/reports/list',
        method: 'get'
      }).then(({data}) => {
        if (data && data.success) {
          this.dataList = data.reports
          this.$http({
            url: '/peopleinformation/identityiformation/peopleIdentityInformation/list',
            method: 'get',
            params: {
              'pageSize': 9999
            }
          }).then(({data}) => {
            if (data && data.success) {
              this.identityArr = data.page.list
            }
          })
          this.loading = false
        }
      })
    },
    add () {
      this.$router.push({path: '/ureport/designer', query: {title: '新建报表', iframeUrl: `${process.env.VUE_APP_SERVER_URL}/ureport/designer`}})
    },
    pre (report) {
      if (this.createdate === '' || this.createdate === null || this.createdate === undefined || this.ticketCount === undefined || this.ticketCount === undefined || this.ticketCount === undefined) {
        this.searchTime = new Date().getFullYear() + '-' + 1
      } else {
        this.searchTime = this.createdate + '-' + this.ticketCount
      }
      if (report.name.split('.')[0] === "考核账号") {
        this.$router.push({path: `/ureport/preview`, query: {title: '预览报表', iframeUrl: `${process.env.VUE_APP_SERVER_URL}/ureport/preview?_u=file:${report.name}&yearTime=${this.searchTime}&ticket=${this.ticket.split(',')[0]}&tickets=${this.ticket.split(',')[1]}`}})
      } else {
        this.$router.push({path: `/ureport/preview`, query: {title: '预览报表', iframeUrl: `${process.env.VUE_APP_SERVER_URL}/ureport/preview?_u=file:${report.name}&yearTime=${this.searchTime}&identity=${this.identity}`}})
      }
    },
    design (report) {
      this.$router.push({path: `/ureport/designer`, query: {iframeUrl: `${process.env.VUE_APP_SERVER_URL}/ureport/designer?_u=file:${report.name}`, title: '编辑报表'}})
    },
  // 删除
    del (report) {
      this.$confirm(`确定删除所选项吗?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.loading = true
        this.$http({
          url: '/reports/delete',
          method: 'delete',
          params: {'id': `file:${report.name}`}
        }).then(({data}) => {
          this.loading = false
          if (data && data.success) {
            this.$message.success(data.msg)
            this.refreshList()
          }
        })
      })
    },
    download (report) {
      if (this.createdate === '' || this.createdate === null || this.createdate === undefined || this.ticketCount === undefined || this.ticketCount === undefined || this.ticketCount === undefined) {
        this.searchTime = new Date().getFullYear() + '-' + 1
      } else {
        this.searchTime = this.createdate + '-' + this.ticketCount
      }
      if (report.name.split('.')[0] === "考核账号") {
        if (this.ticket !== undefined && this.ticket !== '') {
          window.open(`${this.$http.BASE_URL}/ureport/excel?_u=file:${report.name.split('.')[0]}.ureport.xml&yearTime=${this.searchTime}&ticket=${this.ticket.split(',')[0]}&tickets=${this.ticket.split(',')[1]}`)
        }
      } else if (report.name.split('.')[0] === "人员具体测评表") {
        // if (this.peopleName !== undefined && this.peopleName !== '' && this.currentPosition !== undefined && this.currentPosition !== '' && this.appraisalPeopleVal !== undefined && this.appraisalPeopleVal !== '') {
        //   window.open(`${this.$http.BASE_URL}/ureport/excel?_u=file:${report.name.split('.')[0]}&yearTime=${this.searchTime}&peopleName=${this.peopleName}&currentPosition=${this.currentPosition}&appraisalPeopleVal=${this.appraisalPeopleVal}`)
        // }
        this.$http({
          url: '/peopleinformation/peopleassessdata/peopleAssessInformation/list',
          method: 'get',
          params: {
            'pageNo': -1,
            'pageSize': -1,
            'ticketCount': this.searchTime
          }
        }).then(({data}) => {
          if (data && data.success) {
            for (let i in data.page.list) {
               window.open(`${this.$http.BASE_URL}/ureport/excel?_u=file:${report.name.split('.')[0]}.ureport.xml&yearTime=${this.searchTime}&peopleName=${data.page.list[i].name}&currentPosition=${data.page.list[i].currentPosition}&appraisalPeopleVal=fan`)
               window.open(`${this.$http.BASE_URL}/ureport/excel?_u=file:${report.name.split('.')[0]}.ureport.xml&yearTime=${this.searchTime}&peopleName=${data.page.list[i].name}&currentPosition=${data.page.list[i].currentPosition}&appraisalPeopleVal=five`)
            }
          }
        })
      } else if (report.name.split('.')[0] === "单位具体测评表") {
        // if (this.appraisalUnitVal !== undefined && this.appraisalUnitVal !== '') {
        //   window.open(`${this.$http.BASE_URL}/ureport/excel?_u=file:${report.name.split('.')[0]}&yearTime=${this.searchTime}&appraisalUnitVal=${this.appraisalUnitVal}`)
        // }
        this.$http({
          url: '/peopleinformation/peopleassesteam/peopleAssessTeam/list',
          method: 'get',
          params: {
            'pageNo': -1,
            'pageSize': -1,
            'ticketCount': this.searchTime
          }
        }).then(({data}) => {
          if (data && data.success) {
            for (let i in data.page.list) {
              console.log(this.searchTime)
               window.open(`${this.$http.BASE_URL}/ureport/excel?_u=file:${report.name.split('.')[0]}.ureport.xml&yearTime=${this.searchTime}&appraisalUnitVal=${data.page.list[i].oneInstitutional}`)
            }
          }
        })
      } else if (report.name.split('.')[0] === "督学层面干部") {
          window.open(`${this.$http.BASE_URL}/ureport/excel?_u=file:${report.name.split('.')[0]}.ureport.xml&yearTime=${this.searchTime}`)
      } else if (report.name.split('.')[0] === "教学领导班子" || report.name.split('.')[0] === "教辅领导班子") {
          window.open(`${this.$http.BASE_URL}/ureport/excel?_u=file:${report.name.split('.')[0]}.ureport.xml&yearTime=${this.searchTime}`)
      } else {
        if (this.identity !== undefined && this.identity !== '') {
          window.open(`${this.$http.BASE_URL}/ureport/excel?_u=file:${report.name.split('.')[0]}.ureport.xml&yearTime=${this.searchTime}&identity=${this.identity}`)
        }
      }
    }
  }
}
</script>
